import './index.less'

import {inject, observer} from 'mobx-react';
import {WeaDialog, WeaTab, WeaPopoverHrm, WeaMoreButton, WeaRightMenu} from 'ecCom';
import {Button, Col, Row} from 'antd';
import {Condition, getAdButtons} from './Condition';
import {WeaTableNew} from "comsMobx";
import * as mobx from 'mobx';

const WeaTable = WeaTableNew.WeaTable;

@inject("requestListStore")
@observer
export default class Main extends React.Component {
    constructor(props) {
        super(props);
        this.state = {
            height: 510
        }
        const {requestListStore} = props;
        requestListStore.loadCondition();
    }

    componentWillReceiveProps(nextProps) {
        if (this.props.modalVisible !== nextProps.modalVisible && nextProps.modalVisible) {
            const {requestListStore = {}, dataParams = {}} = nextProps;
            requestListStore.updateReportParams && requestListStore.updateReportParams(dataParams);
            requestListStore.doSearch && requestListStore.doSearch();
        }
    }

    render() {
        const {height} = this.state;
        const {requestListStore, params = {}, modalVisible = false, tabDatas = [], collectParams = {}} = this.props;
        const {tableStore, dataKey, selectTabKey = '1', form, showSearchAd, loading = false} = requestListStore;
        const formParams = form.getFormParams() || {};
        return (
            <WeaDialog ecId={`${this && this.props && this.props.ecId || ''}_WeaDialog@n31w7b`} visible={modalVisible}
                       title={'具体流程清单'}
                       style={{'width': 1000, 'height': 510}}
                       icon={'icon-coms-workflow'}
                       iconBgcolor={'#0079DE'}
                       buttons={this.getBottomBtns()}
                       onCancel={this.closeModal.bind(this)}
                       className={"report-request-list-modal"}
                       onChangeHeight={this.changeHeight}
            >
                <WeaRightMenu ecId={`${this && this.props && this.props.ecId || ''}_WeaRightMenu@sdokca`} collectParams={collectParams}>
                    <WeaTab ecId={`${this && this.props && this.props.ecId || ''}_WeaTab@z4ylfv`} datas={tabDatas}
                            keyParam={"key"}
                            selectedKey={selectTabKey}
                            onChange={this.doChangeTab.bind(this)}
                            onSearch={v => {
                                requestListStore.doSearch()
                            }}
                            onSearchChange={v => {
                                requestListStore.setFormFields({requestname: {value: v}})
                            }}
                            searchType={['base', 'advanced']}
                            searchsBaseValue={formParams.requestname}
                            setShowSearchAd={bool => {
                                requestListStore.setShowSearchAd(bool)
                            }}
                            hideSearchAd={() => requestListStore.setShowSearchAd(false)}
                            showSearchAd={showSearchAd}
                            buttonsAd={getAdButtons(requestListStore, this.props && this.props.ecId || '')}
                            searchsAd={
                                <Condition ecId={`${this && this.props && this.props.ecId || ''}_Condition@uo76p6`} requestListStore={requestListStore}/>
                            }
                            loading={loading}
                    />
                    <WeaTable ecId={`${this && this.props && this.props.ecId || ''}_WeaTable@mzu9wu`} sessionkey={dataKey}
                              comsWeaTableStore={tableStore}
                              rowKey={(record, index) => {
                                  return record.rowKeyspan || index;
                              }}
                              scroll={{y: height - 135}}
                    />
                </WeaRightMenu>
                <WeaPopoverHrm ecId={`${this && this.props && this.props.ecId || ''}_WeaPopoverHrm@rs9mik`} inDialog={true}/>
            </WeaDialog>
        )
    }

    getBottomBtns() {
        const {collectParams = {}} = this.props;
        const btns = [];
        //人员办理时间分析表
        btns.push(<Button ecId={`${this && this.props && this.props.ecId || ''}_Button@pio97y@doExportExcel`} type="primary" size="large" onClick={this.doExportExcelEvent.bind(this)}>导出Excel</Button>);
        btns.push(<WeaMoreButton ecId={`${this && this.props && this.props.ecId || ''}_WeaMoreButton@83aq8h@more`} datas={[]} collectParams={collectParams}>更多</WeaMoreButton>);
        return btns;
    }

    doExportExcelEvent() {

    }

    closeModal() {
        const {setListModalVisible, requestListStore = {}, closeModal} = this.props;
        typeof setListModalVisible === 'function' && setListModalVisible(false);
        typeof closeModal === 'function' && closeModal();
        requestListStore.setShowSearchAd(false)
        requestListStore.changeTab("1");
        requestListStore.form && requestListStore.form.reset();
    }

    doChangeTab(selectTabKey) {
        const {changeTab, doSearch} = this.props.requestListStore;
        changeTab && changeTab(selectTabKey);
        doSearch && doSearch();
    }

    changeHeight = (height) => {
        this.setState({height});
    }
}

const showallreceived = (requestid, returntdid) => {
    jQuery.ajax({
        url: "/workflow/search/WorkflowUnoperatorPersons.jsp?requestid=" + requestid + "&returntdid=" + returntdid,
        type: "post",
        success: function (res) {
            try {
                jQuery("#" + returntdid).html(jQuery.trim(res));
                jQuery("#" + returntdid).parent().attr("title", jQuery.trim(res).replace(/[\r\n]/gm, ""))
            } catch (e) {
            }
        }
    });
}

window.showallreceived = showallreceived;